/*
 * Jp_ListesInterventions.java
 *
 * Created on 27 avril 2008, 18:42
 */

package gui;

import IBO.IIntervention;
import boerrors.AdresseInexistantException;
import boerrors.ClientInexistantException;
import boerrors.CodePostalMinimumMultiplicityException;
import boerrors.TechnicienMinimumMultiplicityException;
import boerrors.ZoneMinimumMultiplicityException;
import java.lang.Object;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  olivierm
 */
public class Jp_ListesInterventions extends javax.swing.JPanel {

    private DefaultTableModel _modele = new DefaultTableModel();
    private String[] colName = {"Id","Status","Description de la demande","Priorité demande", "Date demande", "Priorité intervention","Date intervention", "Nom client", "Numéro client","Prénom client", "Matricule Technicien","Nom technicien", "Prénom technicien", "Rue de l'intervention", "Numéro de l'intervention", "Codepostal de l'intervention", "Commune de l'intervention", "Zone de l'intervention"};    
    private Frm_Application _parent = null;
    
    private void fillJtable(Vector<IIntervention> listeI){
        try {

            this._modele.setRowCount(0);
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            String[] listeIntervention = new String[18];
            for (int i = 0; i < listeI.size(); i++) {
                listeIntervention[0] = String.valueOf(listeI.get(i).getIdIntervention());
                listeIntervention[1] = listeI.get(i).getIStatut();
                listeIntervention[2] = listeI.get(i).getDescriptionDemande();
                listeIntervention[3] = listeI.get(i).getPrioriteDemande();
                Date dateDate = listeI.get(i).getDateDemande().getTime();
                String dateFormatee = dateFormat.format(dateDate);
                listeIntervention[4] = dateFormatee;
                if (listeI.get(i).getDateIntervention() != null){
                    listeIntervention[5] = listeI.get(i).getPrioriteIntervention();
                    Date dateDate2 = listeI.get(i).getDateIntervention().getTime();
                    String dateFormatee2 = dateFormat.format(dateDate2);
                    listeIntervention[6] = dateFormatee2;                    
                }
                listeIntervention[7] = String.valueOf(listeI.get(i).getIClient().getIdClient());
                listeIntervention[8] = listeI.get(i).getIClient().getNom();
                listeIntervention[9] = listeI.get(i).getIClient().getPrenom();
                if (listeI.get(i).getITechnicien() != null){
                    listeIntervention[10] = String.valueOf(listeI.get(i).getITechnicien().getMatricule());
                    listeIntervention[11] = listeI.get(i).getITechnicien().getNom();
                    listeIntervention[12] = listeI.get(i).getITechnicien().getPrenom();                    
                }

                listeIntervention[13] = listeI.get(i).getIAdresse().getRue();
                listeIntervention[14] = listeI.get(i).getIAdresse().getNumero();
                listeIntervention[15] = listeI.get(i).getIAdresse().getICodePostal().getCodePostal();
                listeIntervention[16] = listeI.get(i).getIAdresse().getICodePostal().getVille();
                listeIntervention[17] = listeI.get(i).getIAdresse().getICodePostal().getZone().getLibelleZone();
                this._modele.addRow(listeIntervention);
            }
        } catch (ZoneMinimumMultiplicityException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CodePostalMinimumMultiplicityException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        } catch (AdresseInexistantException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        } catch (TechnicienMinimumMultiplicityException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClientInexistantException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
    
    public void initComponents2(Frm_Application parent){
        this._parent = parent;
    }    
    
    /** Creates new form Jp_ListesInterventions */
    public Jp_ListesInterventions() {
        initComponents();
        this._modele.setColumnIdentifiers(colName);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jbtn_ListeInterventions = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jbtn_crees = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jbtn_Planifiees = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jbtn_Deplanifiees = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        jbtn_EnCours = new javax.swing.JButton();
        jSeparator6 = new javax.swing.JToolBar.Separator();
        jbtn_Historique = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jbtn_Suivies = new javax.swing.JButton();
        jSeparator8 = new javax.swing.JToolBar.Separator();
        jbtn_Cloturees = new javax.swing.JButton();
        jSeparator7 = new javax.swing.JToolBar.Separator();
        jbtn_Annulées = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jbtn_Annuler = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        jPanel1.setBackground(new java.awt.Color(0, 102, 153));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 3, 14));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Liste des interventions");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(401, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addContainerGap())
        );

        add(jPanel1, java.awt.BorderLayout.NORTH);

        jXPanel1.setLayout(new java.awt.BorderLayout());

        jToolBar1.setRollover(true);

        jbtn_ListeInterventions.setText("Ouvertes");
        jbtn_ListeInterventions.setFocusable(false);
        jbtn_ListeInterventions.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_ListeInterventions.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_ListeInterventions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_ListeInterventionsActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_ListeInterventions);
        jToolBar1.add(jSeparator1);

        jbtn_crees.setText("Crées");
        jbtn_crees.setFocusable(false);
        jbtn_crees.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_crees.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_crees.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_creesActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_crees);
        jToolBar1.add(jSeparator2);

        jbtn_Planifiees.setText("Planifiées");
        jbtn_Planifiees.setFocusable(false);
        jbtn_Planifiees.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_Planifiees.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Planifiees.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_PlanifieesActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Planifiees);
        jToolBar1.add(jSeparator3);

        jbtn_Deplanifiees.setText("Déplanifiées");
        jbtn_Deplanifiees.setFocusable(false);
        jbtn_Deplanifiees.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_Deplanifiees.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Deplanifiees.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_DeplanifieesActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Deplanifiees);
        jToolBar1.add(jSeparator5);

        jbtn_EnCours.setText("En Cours");
        jbtn_EnCours.setFocusable(false);
        jbtn_EnCours.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_EnCours.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_EnCours.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_EnCoursActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_EnCours);
        jToolBar1.add(jSeparator6);

        jbtn_Historique.setText("Historique");
        jbtn_Historique.setFocusable(false);
        jbtn_Historique.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_Historique.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Historique.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_HistoriqueActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Historique);
        jToolBar1.add(jSeparator4);

        jbtn_Suivies.setText("Suivies");
        jbtn_Suivies.setFocusable(false);
        jbtn_Suivies.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_Suivies.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Suivies.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_SuiviesActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Suivies);
        jToolBar1.add(jSeparator8);

        jbtn_Cloturees.setText("Cloturées");
        jbtn_Cloturees.setFocusable(false);
        jbtn_Cloturees.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_Cloturees.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Cloturees.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_ClotureesActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Cloturees);
        jToolBar1.add(jSeparator7);

        jbtn_Annulées.setText("Annulées");
        jbtn_Annulées.setFocusable(false);
        jbtn_Annulées.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbtn_Annulées.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Annulées.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_AnnuléesActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Annulées);

        jXPanel1.add(jToolBar1, java.awt.BorderLayout.NORTH);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        jTable1.setModel(_modele);
        jScrollPane1.setViewportView(jTable1);

        jXPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        add(jXPanel1, java.awt.BorderLayout.CENTER);

        jbtn_Annuler.setText("Annuler");
        jbtn_Annuler.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_AnnulerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                .addContainerGap(491, Short.MAX_VALUE)
                .addComponent(jbtn_Annuler)
                .addContainerGap())
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbtn_Annuler)
                .addContainerGap())
        );

        add(jXPanel2, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void jbtn_ListeInterventionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_ListeInterventionsActionPerformed
        
        try {
            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionIntervention().listeInterventions();
            fillJtable(listeI);

        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_jbtn_ListeInterventionsActionPerformed

    private void jbtn_creesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_creesActionPerformed
        try {

            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionAPlanifier();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_jbtn_creesActionPerformed

    private void jbtn_PlanifieesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_PlanifieesActionPerformed

        try {

            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionPlanifiee();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }        
        
}//GEN-LAST:event_jbtn_PlanifieesActionPerformed

    private void jbtn_DeplanifieesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_DeplanifieesActionPerformed

        try {

            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionAReplanifier();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }         
        
}//GEN-LAST:event_jbtn_DeplanifieesActionPerformed

    private void jbtn_AnnuléesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_AnnuléesActionPerformed

        try {
            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionAnnulees();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }         
        
        
        
}//GEN-LAST:event_jbtn_AnnuléesActionPerformed

    private void jbtn_AnnulerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_AnnulerActionPerformed

        this._modele.setRowCount(0);
        this.setVisible(false);
        
    }//GEN-LAST:event_jbtn_AnnulerActionPerformed

    private void jbtn_ClotureesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_ClotureesActionPerformed
        
        try {
            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionCloturees();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }         
        
}//GEN-LAST:event_jbtn_ClotureesActionPerformed

    private void jbtn_EnCoursActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_EnCoursActionPerformed
        
        try {

            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionEnCours();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }
        
}//GEN-LAST:event_jbtn_EnCoursActionPerformed

    private void jbtn_SuiviesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_SuiviesActionPerformed
        
         
        try {
            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionSuivies();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }         
        
}//GEN-LAST:event_jbtn_SuiviesActionPerformed

    private void jbtn_HistoriqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_HistoriqueActionPerformed
        
        try {
            Vector<IIntervention> listeI = this._parent.getFactoryRmi().getGestionPlanning().listeInterventionHistorique();
            fillJtable(listeI);
        } catch (RemoteException ex) {
            Logger.getLogger(Jp_ListesInterventions.class.getName()).log(Level.SEVERE, null, ex);
        }         
        
}//GEN-LAST:event_jbtn_HistoriqueActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar.Separator jSeparator6;
    private javax.swing.JToolBar.Separator jSeparator7;
    private javax.swing.JToolBar.Separator jSeparator8;
    private javax.swing.JTable jTable1;
    private javax.swing.JToolBar jToolBar1;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private javax.swing.JButton jbtn_Annuler;
    private javax.swing.JButton jbtn_Annulées;
    private javax.swing.JButton jbtn_Cloturees;
    private javax.swing.JButton jbtn_Deplanifiees;
    private javax.swing.JButton jbtn_EnCours;
    private javax.swing.JButton jbtn_Historique;
    private javax.swing.JButton jbtn_ListeInterventions;
    private javax.swing.JButton jbtn_Planifiees;
    private javax.swing.JButton jbtn_Suivies;
    private javax.swing.JButton jbtn_crees;
    // End of variables declaration//GEN-END:variables
    
}
